<template>
  <view class="p-[32rpx] bg-[#f5f5f5] min-h-screen">
    <view class="text-[36rpx] font-bold text-center mb-[32rpx]">有纠纷状态测试</view>
    
    <!-- 角色切换 -->
    <view class="bg-white rounded-[16rpx] p-[24rpx] mb-[24rpx] shadow-sm">
      <view class="text-[28rpx] font-bold mb-[16rpx]">用户角色</view>
      <view class="flex gap-[12rpx]">
        <nut-button 
          :type="currentUserRole === USER_ROLE.PUBLISHER ? 'primary' : 'default'"
          @click="currentUserRole = USER_ROLE.PUBLISHER"
        >
          发布方
        </nut-button>
        <nut-button 
          :type="currentUserRole === USER_ROLE.APPLICANT ? 'primary' : 'default'"
          @click="currentUserRole = USER_ROLE.APPLICANT"
        >
          接单人
        </nut-button>
      </view>
    </view>

    <!-- 有纠纷状态测试 -->
    <view class="bg-white rounded-[16rpx] p-[24rpx] shadow-sm">
      <view class="text-[28rpx] font-bold mb-[16rpx] text-[#fa541c]">有纠纷状态</view>
      <RewardTaskItem
        :item="disputeTask"
        @communicatePlatform="handleCommunicatePlatform"
        @acceptSolution="handleAcceptSolution"
        @rejectSolution="handleRejectSolution"
      />
    </view>

    <!-- 调试信息 -->
    <view class="bg-white rounded-[16rpx] p-[24rpx] mt-[24rpx] shadow-sm">
      <view class="text-[24rpx] font-bold mb-[12rpx]">调试信息</view>
      <view class="text-[20rpx] text-[#666] space-y-[8rpx]">
        <view>用户角色: {{ currentUserRole === USER_ROLE.PUBLISHER ? '发布方' : '接单人' }}</view>
        <view>任务状态: {{ disputeTask.taskStatus }}</view>
        <view>用户状态: {{ disputeTask.userStatus }}</view>
        <view>可用操作: {{ availableActions.join(', ') }}</view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from "vue";
import { Button as nutButton } from "@nutui/nutui-taro";
import Taro from "@tarojs/taro";
import RewardTaskItem from "./RewardTaskItem.vue";
import { 
  TASK_STATUS, 
  APPLICANT_STATUS, 
  PUBLISHER_STATUS, 
  USER_ROLE,
  getAvailableActions
} from "@/constants/taskStatus";

// 当前用户角色
const currentUserRole = ref(USER_ROLE.PUBLISHER);

// 有纠纷的任务数据
const disputeTask = computed(() => ({
  id: 1,
  taskTitle: "有纠纷的测试任务",
  status: "有纠纷",
  taskStatus: TASK_STATUS.DISPUTED,
  userRole: currentUserRole.value,
  userStatus: currentUserRole.value === USER_ROLE.PUBLISHER ? PUBLISHER_STATUS.DISPUTED : APPLICANT_STATUS.DISPUTED,
  totalReward: "500.00",
  applyCount: 1,
  desc: "这是一个有纠纷的任务，用于测试按钮显示是否正确",
  isUrgent: true,
  pay_status: 1,
  deadline: "2024-01-15",
}));

// 获取可用操作
const availableActions = computed(() => {
  return getAvailableActions(
    disputeTask.value.taskStatus,
    disputeTask.value.userRole,
    disputeTask.value.userStatus
  );
});

// 事件处理函数
const handleCommunicatePlatform = (task) => {
  Taro.showToast({ title: `联系平台: ${task.taskTitle}`, icon: 'none' });
};

const handleAcceptSolution = (task) => {
  Taro.showToast({ title: `接受方案: ${task.taskTitle}`, icon: 'none' });
};

const handleRejectSolution = (task) => {
  Taro.showToast({ title: `拒绝方案: ${task.taskTitle}`, icon: 'none' });
};
</script>
